﻿//
// Copyright (c) 2024 BPer
//

#ifndef INCLUDE_BPERCAPTURE_BPERRENDERAUDIODATA_H_
#define INCLUDE_BPERCAPTURE_BPERRENDERAUDIODATA_H_
#include <bperutil/BPerAvInfoType.h>

#include <bperutil/buffer/BPerAudioPlayBuffer.h>
#include <bperavutil/audio/BPerPreProcess.h>
#include <bperavutil/audio/BPerAudioUtil.h>

#include <bperstream/BPerSynBuffer.h>


class BPerAudioRenderData {
public:
    BPerAudioRenderData();
    virtual ~BPerAudioRenderData();

public:

    BPerSynBuffer* m_syn;
    BPerPreProcess* m_preProcess;
    BPerAudioResample m_res;
    void setAec();
    void setRenderLen(int plen);
    void setContext(BPerSynBufferManager* streams);
    void initRender(int psample,int pchannel);
    void initPlay(int psample,int pchannel);
    uint8_t* getAudioRef(BPerFrame* pframe);
    uint8_t* getRenderAudioData(int len);
    uint8_t* getAecAudioData();
    void setInAudioBuffer(BPerSynBuffer *pal);


private:
    bool m_hasAec;
    int m_aecBufLen;
    int m_mixPos;
    int m_renderLen;
    uint8_t* m_aecBuf;


    uint8_t* m_cache;
    int m_cacheLen;
    int m_size;
    int m_pos;

    uint8_t* m_mixBuf;
    BPerSynBufferManager* m_syns;

    BPerFrame m_audioFrame;



private:

    uint8_t* getAudioData(BPerFrame* frame);

    void setAudioData(BPerFrame* frame);


};

#endif /* INCLUDE_BPERCAPTURE_BPERRENDERAUDIODATA_H_ */
